package com.definesys.smecrailtransit.module.LinkPage;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.definesys.smecrailtransit.R;
import com.definesys.smecrailtransit.SmecManager.SmecSession.SmecSession;
import com.definesys.smecrailtransit.base.SmecBaseActivity;
import com.definesys.smecrailtransit.databinding.ActivityLinkPageBinding;
import com.definesys.smecrailtransit.module.LinkPage.fragment.LinkPageFragementFive;
import com.definesys.smecrailtransit.module.LinkPage.fragment.LinkPageFragementFour;
import com.definesys.smecrailtransit.module.LinkPage.fragment.LinkPageFragementOne;
import com.definesys.smecrailtransit.module.LinkPage.fragment.LinkPageFragementThree;
import com.definesys.smecrailtransit.module.LinkPage.fragment.LinkPageFragementTwo;
import com.definesys.smecrailtransit.module.LinkPage.fragment.LinkPageFragmentSix;
import com.github.mzule.activityrouter.router.Routers;

import java.util.ArrayList;


/**
 * Created by cjy on 2018/1/2.
 */

public class LinkPageActivity extends SmecBaseActivity{

    private ActivityLinkPageBinding activityLinkPageBinding;
    private int currentPage;
    private ArrayList<Fragment> fragments = new ArrayList<>();


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(!SmecSession.getSmecUser().isLinkpage()){
            Routers.open(LinkPageActivity.this,"smec://LoginActivity");
            this.onStop();
        }
        activityLinkPageBinding = DataBindingUtil.setContentView(this, R.layout.activity_link_page);
        currentPage = 0;
        _initData();
        _initView();
    }

    @Override
    public Object getPresenter() {
        return null;
    }

    private void _initView(){
        activityLinkPageBinding.pager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }
        });

        activityLinkPageBinding.pager.setOffscreenPageLimit(fragments.size());
        activityLinkPageBinding.pager.setCurrentItem(0,false);
        activityLinkPageBinding.pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
            @Override
            public void onPageSelected(int position) {}
            @Override
            public void onPageScrollStateChanged(int state) {}
        });

    }

    private void _initData(){
        fragments.add(LinkPageFragementOne.newInstance());
        fragments.add(LinkPageFragementTwo.newInstance());
        fragments.add(LinkPageFragementThree.newInstance());
        fragments.add(LinkPageFragementFour.newInstance());
        fragments.add(LinkPageFragementFive.newInstance());
        fragments.add(LinkPageFragmentSix.newInstance());
    }
}
